const { Service } = require("egg");
const { Op } = require("sequelize");


class TopicTeacherService extends Service {

    async list(topicId) {
        return await this.app.model.TopicTeacher.findAll(
            {
                where: {
                    topicId
                },
                order: [['updatedAt', 'DESC']],
                raw: true,
            }
        );
    }
    async create(data) {

        return await this.app.model.TopicTeacher.create(data);
    }

    async delete(id) {
        return await this.app.model.TopicTeacher.destroy({
            where: { id },
        });
    }

    async update(id, updateData) {

        const TopicInfo = await this.app.model.TopicTeacher.findOne({
            where: { id },
        });
        if (TopicInfo) {

            const updatedTopic = await this.app.model.TopicTeacher.update(
                updateData,
                {
                    where: { id: id },
                });
            return updatedTopic[0] ? updatedTopic[0] : null;
        }
        return null;
    }
}

module.exports = TopicTeacherService;
